clear all
set more off
cap log close

adopath + "H:\Lavecchia_7086\to-transfer-jan-2022\reghdfe_files"
adopath + "H:\Lavecchia_7086\to-transfer-jan-2022\binscatter_files"

do "H:\Lavecchia_7086\to-transfer-jan-2022\RESTAT_Replication_Programs\0_Set_Directories.do"
*do "H:\Lavecchia_7086\to-transfer-jan-2022\1_Alisa_Do\0_Set_Directories.do"


cap log close
cap log using "$dir_log\3h_Baselie_Regression_Specifications_Set_Sample.log", replace

clear
use "$dir_data\data_sample_IV_diffndiff.dta"

/* Added by Adam on October 13, 2020 */
gen group_5h = (clkgxi8593 >= 25000 & clkgxi8593 < 50000)  
drop if cg_8593 == 5 & group_5h == 0
drop if cg_8593 == 6

gen flag = (clkgxi8593 == .)
drop if flag == 1
drop flag

/* End added by Adam on October 13, 2020 */

*drop if year < 1990
*drop if year > 1999
drop if flag_losses == 1


gen log_clkgxi = log(1 + clkgxi)
gen ihs_clkgxi = log(clkgxi + (1 + clkgxi^2)^(0.5))

gen treat_cg_8593 = (cg_8593 >= 3)
gen T_event = treat_cg_8593*(year - 1994)
replace T_event = -1 if treat_cg_8593 == 0
recode T_event (.=-1)  (-1000/-10=-10)  (12/10000=12)
*recode T_event (.=-1)
char T_event[omit] -1
xi i.T_event, pref(_)


* Create a variable for 1994 realized capital gains in case we want to add this later
* Added by Adam on August 5, 2020
gen cg94 = clkgxi if year == 1994
sort lin__i year
replace cg94 = cg94[_n - 1] if cg94 == . & lin__i == lin__i[_n - 1] & year == (year[_n - 1] + 1) & year >= 1995
replace cg94 = cg94[_n + 1] if cg94 == . & lin__i == lin__i[_n + 1] & year == (year[_n + 1] - 1) & year == 1993
replace cg94 = cg94[_n + 1] if cg94 == . & lin__i == lin__i[_n + 1] & year == (year[_n + 1] - 1) & year == 1992
replace cg94 = cg94[_n + 1] if cg94 == . & lin__i == lin__i[_n + 1] & year == (year[_n + 1] - 1) & year == 1991
replace cg94 = cg94[_n + 1] if cg94 == . & lin__i == lin__i[_n + 1] & year == (year[_n + 1] - 1) & year == 1990



* Save versions for unconditional and intensive margin analysis
* Added by Adam on August 5, 2020
save "$dir_data\data_sample_DD_unconditional.dta", replace
preserve

keep if clkgxi > 0
save "$dir_data\data_sample_DD_intensive.dta", replace
restore
